package com.niit.agricstore.controller;

import com.github.pagehelper.PageInfo;
import com.niit.agricstore.entity.AfterSale;
import com.niit.agricstore.service.AftersaleService;
import com.niit.agricstore.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/aftersale")
@Slf4j
public class AftersaleController {
    @Autowired
    private AftersaleService aftersaleService;
    //查询售后数据
    @GetMapping("/{aftersale_id}")
    public AfterSale getAftersaleById(@PathVariable int aftersale_id) {
        return aftersaleService.getAftersaleById(aftersale_id);
    }
    //查询所有售后记录
    @GetMapping("/all")
    public Result getAllByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        log.info("==========================================");
        PageInfo pageInfo = aftersaleService.findAllByPage(pageNum, pageSize);
        System.out.println("=====pageInfo======:" + pageInfo);
        if (pageInfo != null) {
            return Result.success("200", "分页显示所有商品成功", pageInfo);
        } else {
            return Result.error("202", "分页显示所有商品失败");
        }
    }

    //更新售后状态
    @PutMapping("/{aftersale_id}/updateStatus")
    public Result updateAftersaleStatus(@PathVariable int aftersale_id, @RequestParam String aftersale_state) {
        return aftersaleService.updateAftersaleStatus(aftersale_id, aftersale_state);
    }
}
